package at.fhooe.stefanirndorfer.collision;

import at.fhooe.stefanirndorfer.entity.Entity;
import at.fhooe.stefanirndorfer.walls.Wall;

public class CollisionDetector {

	/**
	 * 
	 * @param e
	 * @param x
	 * @param y
	 * @return
	 */
	public static boolean hasCollisionPointRect(Entity e, int x, int y){
		
		int upperLeftX = (int) e.getPosX();
		int lowerRightX = upperLeftX + (int)e.getWidth();
		int upperLeftY = (int) e.getPosY();
		int lowerRightY = upperLeftY - (int)e.getHeight();
		
		if(x < upperLeftX) return false;
		if( x > lowerRightX) return false;
		if(y > upperLeftY) return false;
		if(y < lowerRightY) return false;
		return true;
	}

	
	
	
	public static boolean hasBoxIntersection(Entity e, double[] upperLeft,
			double[] lowerRight) {
		
		int upperLeftXE = (int) e.getPosX();
		int lowerRightXE = upperLeftXE + (int)e.getWidth();
		int upperLeftYE = (int) e.getPosY();
		int lowerRightYE = upperLeftYE - (int)e.getHeight();
		
		if(lowerRightXE < upperLeft[0] || upperLeftXE > lowerRight[0])
			return false;
		if(upperLeftYE < lowerRight[1] || lowerRightYE > upperLeft[1])
			return false;
		
		return true;
	}

	public static boolean isTotallyIncluded(Wall e, double[] upperLeft,
			double[] lowerRight) {
		
		int upperLeftXE = (int) e.getPosX();
		int lowerRightXE = upperLeftXE + (int)e.getWidth();
		int upperLeftYE = (int) e.getPosY();
		int lowerRightYE = upperLeftYE - (int)e.getHeight();
		
		if(upperLeft[0] >= upperLeftXE && lowerRight[0] <= lowerRightXE
				&&
				upperLeft[1] <= upperLeftYE && lowerRight[1] >= lowerRightYE)
			return true;
		
		return false;
	}
	
	
}
